package cn.yunhe.controller;

import cn.yunhe.entity.User;
import cn.yunhe.service.UserService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.SessionAttributes;
import org.springframework.web.servlet.ModelAndView;

import java.util.HashMap;

@Controller
@SessionAttributes(value = "names,user,userId", types = Integer.class)
public class LoginController {
    /*@RequestParam 等同于 RequestParameter */

    @RequestMapping("/login")
    public ModelAndView login(User user, @RequestParam Integer id, HashMap<String, Object> map) {
        ModelAndView mv = new ModelAndView();
        UserService userService = new UserService();
        if (userService.login(user) > 0) {
            /*ModelAndView存值默认村在request域中*/
            map.put("user", user);
            map.put("userId", id);
            mv.setViewName("succ");
            return mv;
        } else {
            mv.setViewName("login");
            return mv;
        }
    }


}
